from django.db import models
from datetime import datetime

# Create your models here.

class Card(models.Model):
    photo = models.ImageField(upload_to='/tmp')
    nickname = models.CharField(maxlength="50")
    name = models.CharField(maxlength="20")
    location = models.CharField(maxlength="80")
    post = models.CharField(maxlength="60")
    email = models.EmailField()
    created = models.DateTimeField(default=datetime.now)
    
    def __str__(self):
        return self.nickname

    def get_absolute_url(self):
        return "/card/%s/" % self.nickname

    class Admin:
        pass

class Connection(models.Model):
    source = models.ForeignKey(Card, related_name='source_card')
    target = models.ForeignKey(Card, related_name='target_card')
    created = models.DateTimeField(default=datetime.now)
    
    def __str__(self):
        return str(self.source) + "+" + str(self.target)

    class Admin:
        pass

class Story(models.Model):
    connection = models.ForeignKey(Connection)
    when = models.DateField()
    where = models.CharField(maxlength="80")
    who = models.CharField(maxlength="40")
    why = models.TextField()
    created = models.DateTimeField(default=datetime.now)

    def __str__(self):
        return str(self.connection)

    class Admin:
        pass
